home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / nevow / compy.py < prev    next >
Text File  |  2006-03-08  |  2KB  |  62 lines

  1. # Copyright (c) 2004 Divmod.
  2. # See LICENSE for details.
  3.  
  4. """Compatibility wrapper over new twisted.python.components,
  5. so that nevow works with it. 
  6. """
  7.  
  8. import warnings
  9.  
  10. from zope.interface import Interface, implements as zimplements, Attribute
  11.  
  12. from twisted.python.components import *
  13.  
  14. warnings.warn("compy.py module is deprecated, use zope.interface and twisted.python.components.registerAdapter directly.",
  15.               stacklevel=2)
  16.  
  17. # Backwards compat code
  18. CannotAdapt = TypeError
  19.  
  20. _registerAdapter = registerAdapter
  21. def registerAdapter(adapterFactory, origInterface, *interfaceClasses):
  22.     from nevow.util import _namedAnyWithBuiltinTranslation, _NamedAnyError
  23.     
  24.     isStr = type(adapterFactory) is str
  25.     if (type(origInterface) is str) != isStr:
  26.         raise ValueError("Either all arguments must be strings or all must be objects.")
  27.     
  28.     for interfaceClass in interfaceClasses:
  29.         if (type(interfaceClass) is str) != isStr:
  30.             raise ValueError("Either all arguments must be strings or all must be objects.")
  31.  
  32.     if isStr:
  33.         # print "registerAdapter:",adapterFactory, origInterface, interfaceClasses
  34.         adapterFactory = _namedAnyWithBuiltinTranslation(adapterFactory)
  35.         origInterface = _namedAnyWithBuiltinTranslation(origInterface)
  36.         interfaceClasses = [_namedAnyWithBuiltinTranslation(x) for x in interfaceClasses]
  37.  
  38.     if 'nevow.inevow.ISerializable' in interfaceClasses or filter(
  39.             lambda o: getattr(o, '__name__', None) == 'ISerializable', interfaceClasses):
  40.         warnings.warn("ISerializable is deprecated. Please use nevow.flat.registerFlattener instead.", stacklevel=2)
  41.         from nevow import flat
  42.         flat.registerFlattener(adapterFactory, origInterface)
  43.     _registerAdapter(adapterFactory, origInterface, *interfaceClasses)
  44.  
  45.  
  46. class IComponentized(Interface):
  47.     pass
  48.  
  49. _Componentized = Componentized
  50. class Componentized(_Componentized):
  51.     zimplements(IComponentized)
  52.     
  53.     def __init__(self, adapterCache=None):
  54.         _Componentized.__init__(self)
  55.         if adapterCache:
  56.             for k, v in adapterCache.items():
  57.                 self.setComponent(k, v)
  58.  
  59.  
  60. __all__ = ['globalRegistry', 'registerAdapter', 'backwardsCompatImplements', 'fixClassImplements',
  61.            'getInterfaces', 'IComponentized', 'Componentized', 'Adapter', 'CannotAdapt']
  62.